package com.zj.study.controller;

import com.zj.study.feign.ProviderFeignClient;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.client.RestTemplate;

/**
 * @author 赵赳
 * @since 2021/12/5 00:16
 */
@RestController
public class ConsumerController {

    private final RestTemplate restTemplate;

    private final ProviderFeignClient providerFeignClient;

    public ConsumerController(RestTemplate restTemplate, ProviderFeignClient providerFeignClient) {
        this.restTemplate = restTemplate;
        this.providerFeignClient = providerFeignClient;
    }

    /**
     * test feign demo
     * @param a a
     * @param b b
     * @return 结果
     */
    @GetMapping("/test/feign/{a}/{b}")
    public int testFeignClient(@PathVariable("a") int a,@PathVariable("b") int b){
        return providerFeignClient.sum(a, b);
    }

    /**
     * test
     * @param name name
     * @return 结果
     */
    @GetMapping("/test")
    public String test(String name) {
        return restTemplate.getForObject("http://nacos-discovery-provider/demo?name=" + name, String.class);
    }


}
